import Vue from 'vue'
import Vuex from 'vuex'
import createPresistedState from 'vuex-persistedstate';
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
	  user:"",
	  user_id:"",
	  allNum:0,
	  cartData:[],
	  nOrder:[]
  },
  mutations: {
	  setUser(state,user){
		  state.user = user.userName
		  state.user_id = user.user_id
	  },
	  delUser(state){
		  state.user = ""
		  state.user_id = ""
		  state.allNum = 0
	  },
	  setCartData(state,data){
		  state.allNum = 0
		  data.forEach(item=>{
			  item.money = item.num*item.price
			  item.visible = false
			  state.allNum += item.num
		  })
		  state.cartData = data
	  },
	  setOrder(state,val){
		 state.nOrder = val
	  }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    createPresistedState()
  ]
})
